Skip to content

fix db credentials - #212

Open
MJoaaquin wants to merge 1 commit into
masterfrom
fix-db-credentials
Open

fix db credentials#212
MJoaaquin wants to merge 1 commit into
masterfrom
fix-db-credentials

Conversation

@MJoaaquin

@MJoaaquin MJoaaquin commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

IMPORTANT

before merge this PR we should add the following vars:

  • PROD_POSTGRES_DB
  • PROD_POSTGRES_USER

And secrets:

  • PROD_POSTGRES_PASSWORD
  • PROD_COOKIE_SECRET

in the github CI settings

One-time DB version realignment (if the target env has drift)

Previously, we didn't wait for the result of the service that ran the migrations, so they failed silently. We've now added code to check whether the migrations ran successfully, but this revealed on the development branch that some tables had been created outside the migration flow, causing the table that tracks them to fall behind.

Here's what I did to fix this problem in the development branch

If the deploy fails at the migration step with column "..." already exists /
relation "..." already exists, the DB schema is ahead of alembic_version
(something was applied out-of-band). Temporarily add a stamp before the normal
migration run, in the deploy step of the workflow, between pull and up -d:

             # Pull and deploy
             docker compose -f compose.yml pull
+            # ONE-TIME: DB has schema changes applied out-of-band while alembic_version
+            # is behind. Realign the version pointer so the pending migrations can apply.
+            # REMOVE this line after the deploy that fixes it.
+            docker compose -f compose.yml run --rm -T chatmap-api-migrate uv run alembic stamp <REV>
+            # Run migrations in the foreground so alembic output/errors land in the CI log
+            docker compose -f compose.yml run --rm -T chatmap-api-migrate
             docker compose -f compose.yml up -d chatmap-ui chatmap-api chatmap-nginx chatmap-api-migrate chatmap-go --force-recreate

<REV> = the revision that matches the real schema (check first with
docker compose -f compose.yml run --rm -T chatmap-api-migrate uv run alembic current).
For dev it was b7b2a3b424b8 (schema had maps.description, version was at 74a24da4d758).

alembic stamp <REV> writes the revision into alembic_version without running
any migration DDL.

Remove both added lines after a successful deploy — otherwise the next deploy
stamps alembic_version backwards and upgrade head fails recreating an existing table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant